package cn.hznc.webstocket;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author：Administrator
 * @Date：2024/3/1 11:45
 */
@Component
public class SpringAware implements ApplicationContextAware {

    private static ApplicationContext APPLICATION_CONTEXT;
    @Override
    public void setApplicationContext(ApplicationContext app) throws BeansException {
        APPLICATION_CONTEXT = app;
    }
    public static ApplicationContext getContext(){
        return APPLICATION_CONTEXT;
    }
    public static Object getBean(String beanName){
        return APPLICATION_CONTEXT.getBean(beanName);
    }

    public static <T> T getBean(Class<T> clazz){
        return (T)APPLICATION_CONTEXT.getBean(clazz);
    }

}
